Page({
  data: {
      anchor_id: 0,
      list: [],
      loading: false,
      page: 1,
      isStop: false,
  },
  onLoad: function(t) {
      getApp().page.onLoad(this, t)
      if (t.anchor_id) {
          this.setData({
              anchor_id: t.anchor_id
          })
      }
      this.getList()
  },

  /**
     * 点击直播
     */
    onClickLive: function (e) {
        let item = e.currentTarget.dataset.item
        wx.navigateTo({
            url: '/lives/live/live?room_id=' + item.id
        })
    },

  getList: function () {
      wx.showLoading({
          title: '加载中...',
      });
      this.setData({
          isStop: false
      })
      getApp().request({
          url: getApp().api.live.get_live_log,
          data: {
              anchor_id: this.data.anchor_id
          },
          success: data => {
              if (data.code == 0) {
                  this.setData({
                      list: data.data.list
                  })
              }
          },
          complete: () => {
              this.setData({
                  loading: true
              });
              wx.hideLoading();
          }
      });
  },

  onReachBottom: function() {
      if (this.data.isStop) {
          return;
      }
      wx.showLoading({
          title: '加载中...',
      });
      getApp().request({
          url: getApp().api.live.get_live_log,
          data: {
              page: this.data.page + 1,
              anchor_id: this.data.anchor_id
          },
          success: data => {
              if (data.code == 0) {
                  if (data.data.list.length > 0) {
                      this.setData({
                          list: this.data.list.concat(data.data.list),
                          page: this.data.page + 1
                      });
                  } else {
                      this.setData({
                          isStop: true
                      });
                  }
              } else {
                  wx.showToast({
                      title: data.msg,
                      icon: 'none'
                  });
              }
          },
          complete: () => {
              wx.hideLoading();
          }
      });
  },
  onShow: function() {
      getApp().page.onShow(this);
  }
});